package cn.wetcland.es.controller;

import cn.wetcland.es.dto.GroupBindStuDTO;
import cn.wetcland.es.dto.GroupDeleteDTO;
import cn.wetcland.es.dto.GroupRemoveStuDTO;
import cn.wetcland.es.service.EsGroupService;
import cn.wetcland.es.utils.MyAssert;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/manageGroup")
public class ManageGroupController {

    @Resource
    private EsGroupService groupService;

    @RequestMapping("/delete")
    public String deleteGroup(GroupDeleteDTO groupDeleteDTO, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        groupService.deleteGroup(groupDeleteDTO);
        return "redirect:/manageGroup?classId=" + groupDeleteDTO.getClassId();
    }

    @RequestMapping("/removeStu")
    public String removeStu(GroupRemoveStuDTO groupRemoveStuDTO, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        groupService.removeStu(groupRemoveStuDTO);
        return "redirect:/manageGroup?classId=" + groupRemoveStuDTO.getClassId();
    }

    @RequestMapping("/bind")
    public String bindStuGroup(GroupBindStuDTO groupBindStuDTO, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        groupService.bindStuGroup(groupBindStuDTO);
        return "redirect:/manageGroup?classId=" + groupBindStuDTO.getClassId();
    }

}
